from multiprocessing import Pool, cpu_count
import os, time

def worker(name):
    print(f'子进程名：{name}，子进程ID：{os.getpid()}')
    start = time.time()
    time.sleep(1)
    # print(f'子进程{name}运行时间：{time.time() - start}')

if __name__ == '__main__':
    print(f'主线程ID：{os.getpid()}')
    print('start')
    cpu_num = cpu_count()
    print(f'当前计算机CPU核数量：{cpu_num}')
    p = Pool(cpu_num) # 创建进程池
    for i in range(10):
        p.apply_async(worker, args=(f'process{i}',))
    p.close()
    p.join()
    print('end')